#!/bin/bash
#########################################################################
# File Name: 360-parse.sh
# Author: Fan Yang
# mail: missdeer@dfordsoft.com
# Created Time: 2014年02月24日 星期一 20时53分58秒
#########################################################################
grep -r -a "'tbg3'>[0-9]\+<\/td>" -o $1 | grep -o "[0-9]\{7,\}" > /tmp/360.issue
grep -r -a "td width='33'>[0-9]\+</td>" -o $1 | grep -o "[0-9]\+" |
{
    rm -f /tmp/360.tmp
    while read w && read b
    do 
        echo $b >> /tmp/360.tmp
    done
}
grep -r -a "width='33'>[0-9]\+</b>" -o $1 | grep -o "[0-9]\+" |
{
    while read w && read b
    do 
        echo $b >> /tmp/360.tmp
    done
}
rm -f /tmp/360.data
cat /tmp/360.tmp | while read c1 && read c2 && read c3 && read c4 && read c5 && read c6 && read c7 && read c8 && read c9 && read c10
do
    echo "$c1 $c2 $c3 $c4 $c5 $c6 $c7 $c8 $c9 $c10" >> /tmp/360.data
done
paste -d " " /tmp/360.issue /tmp/360.data > /tmp/360.txt
cat /tmp/360.txt | while read line
do
    issue=`echo "$line" | awk '{print $1}'`
    ball=`echo "$line" | awk '{print $2}'`
    if [[ "-$ball" != "-" ]]
    then
        valid_issue=`echo "$issue" | grep -o "[0-9]\{7,7\}"`
        if [[ "-$valid_issue" != "-" ]]
        then
            exist=`grep -r -a "$issue" $2`
            if [[ "-$exist" = "-" ]]
            then
                echo "$line" >> $2 
            fi
        fi
    fi
done
